package com.poetize.plus.entity.dto;

import com.poetize.plus.entity.po.Notice;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Null;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Update;

/**
 * @Author zuosy
 * @Date 2024/3/30 14:48
 **/
public record NoticeDTO(
        @Schema(description = "id")
        @Null(message = "id必须为空", groups = {Insert.class})
        @NotNull(message = "id不能为空", groups = {Update.class})
        Long id,

        @Schema(description = "公告标题")
        @NotBlank(message = "公告标题不能为空", groups = {Insert.class, Update.class})
        String title,

        @Schema(description = "公告内容")
        @NotBlank(message = "公告内容不能为空", groups = {Insert.class, Update.class})
        String content,

        @Schema(description = "是否启用")
        @NotNull(message = "是否启用不能为空", groups = {Insert.class, Update.class})
        Boolean status
) {

        /**
         * DTO转实体类
         * @param noticeDTO
         * @return
         */
        public static Notice convertDTO(NoticeDTO noticeDTO){
                return new Notice(noticeDTO.id, noticeDTO.title, noticeDTO.content, noticeDTO.status);
        }
}
